package com.ylc.service.impl;

import com.ylc.domain.Accounts;
import com.ylc.mapper.AccountMapper;
import com.ylc.service.AccountsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: ylc
 * @Description:
 * @Date Created in 2022-07-20 16:56
 */
@Service
/*// 基于注解方式实现事务
@Transactional(propagation = Propagation.REQUIRED, // 事务的传播特性
        // 发生算数异常ArithmeticException不回滚，使用异常的名称
        noRollbackForClassName = "ArithmeticException",
        // ..................................,使用异常的类型
        // noRollbackFor = ArithmeticException.class
        // rollbackForClassName = "ArithmeticException" 指定发生ArithmeticException异常必须回滚
        timeout = -1,   // 连接超时设置，默认是-1表示永不超时
        readOnly = false,   // 默认是false，如果是查询操作，必须设置为true
        isolation = Isolation.DEFAULT // 使用数据库自己的隔离级别
)*/
public class AccountsServiceImpl implements AccountsService{
    @Autowired
    AccountMapper accountMapper;

    @Override
    public int save(Accounts accounts) {
        int num = accountMapper.save(accounts);
        System.out.println("账户添加成功！num=" + num);
        System.out.println(1/0);
        return num;
    }
}
